﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS
{
    public partial class Content : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null)
            {
                int id = int.Parse(Request.QueryString["ID"].ToString());
                cmsCategoryDO objCat = new cmsCategoryDO();
                objCat.CategoryID = id;
                objCat = new cmsCategoryBL().Select(objCat);
                string host = Request.Url.Host;
                if (host.ToLower().Equals("localhost") || host.ToLower().Equals("cayxanhdangviet.com"))
                {
                    Page.Title = objCat.Title + " | " + Ultility.WebTitle(true);
                }
                else
                {
                    Page.Title = objCat.Title + " | " + Ultility.WebTitle(false);
                }
                lblInfo.Text = objCat.DetailContent;
                DataTable dt = new cmsCategoryBL().SelectAll();
                if (!IsPostBack)
                {
                    rptOther.DataSource = new DataView(dt, "IsContent = true AND ParentID >0 AND CategoryID <> " + id, "OrderID ASC, CategoryID DESC", DataViewRowState.CurrentRows);
                    rptOther.DataBind();
                    rptAlbumDataSoucre(id);
                }
            }
        }
        protected void rptAlbumDataSoucre(int categoryID)
        {
            rptAlbum.DataSource = new cmsAlbumBL().SelectByCate(categoryID);
            rptAlbum.DataBind();

        }
        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
        public string CheckDate(string sDate)
        {
            if (sDate != null)
            {
                //kiem tra ngay thang neu nho hon ngay hien tai (chu y parse sang datetime) 
                DateTime startDate = Convert.ToDateTime(sDate);
                DateTime now = DateTime.Now;
                TimeSpan elapsed = now.Subtract(startDate);
                double daysAgo = elapsed.TotalDays;
                if (daysAgo < 30)
                {
                    //return "<span class=\"red\">" + sDate; 
                    //return "<asp:Image ID=\"imgNew\" ImageUrl=\"~/images/New_icons_07.gif\" runat=\"server\" AlternateText=\"New\" />";
                    return "<img src=\"/images/New_icons_07.gif\" AlternateText=\"New\" />";
                }
                else
                {
                    return " ";
                }
            }
            else
            {
                return "";
            }
        }
    }
}
